class StopCondition:
	
	
	def __init__(self, stop_parameters):
		"""
		Recebe o nome da funcar de paragem e os seus parametros numa lista: (max_generation,best)
		"""
		self.generation_limit = stop_parameters[1]
		self.target_quality = stop_parameters[0]


	def generation_or_quality(self, generation, best_one):
		if(self.generation_end(generation) |\
		   self.quality_achieved(best_one)):
			return True
		else:
			return False
	
	def generation_or_quality_stop(self):
		return (lambda time,best: self.generation_or_quality(time,best))

	
	## Needs the generations
	def generation_end(self, num_ger):
		if(num_ger>=self.generation_limit):
			return True
		else:
			return False

	def generation_end_stop(self):
		return (lambda time,best: self.generation_end(time))


	## Needs the best one in the pop
	def quality_achieved(self, best_quality):
		if(best_quality>=self.target_quality):
			return True
		else:
			return False

	def quality_achieved_stop(self):
		return (lambda time,best: self.quality_achieved(best))


